'''
Created on 2010-1-19

@author: wangjo
'''

import model
import utility
import logging

class IndexHandler(utility.BaseRequestHandler):
    def get(self):
        page = self.pageHandler()
        limit = self.limitHandler()
        offset = (page -1)*limit
        feedbacks = model.Feedback.get_feedbacks(limit, offset)
        self.generate('support.index.html', {'app_name': 'Taobility Support',
                                             'selected' : 'support',
                                             'feedbacks': feedbacks,})
    def post(self):
        val_name = self.request.get("field_name", "annoymous")
        val_email = self.request.get("field_email", None)
        val_app = self.request.get("field_app", None)
        val_content = self.request.get("field_content", None)
        result = False
        msg = ""
        if val_name and val_email and val_content:
            result = True
            model.Feedback.add_feedback(name=val_name, email=val_email, content= val_content, app=val_app)
            msg = "Thank you for your feedback, and we will contact you soon if necessary!"
        else:
            msg = "Sorry, Email and Feedback are required fields."
        page = self.pageHandler()
        limit = self.limitHandler()
        offset = (page -1)*limit
        feedbacks = model.Feedback.get_feedbacks(limit, offset)
        self.generate('support.index.html', {'app_name': 'Taobility Support',
                                             'selected' : 'support',
                                             'feedbacks': feedbacks, 
                                             'result':result, 
                                             'status': msg,})